<?php
class Admin_Form_Advertisement extends Zend_Form {
	
	const POSITION = 'Vị trí hiển thị';
	const PAGE = 'Trang hiển thị';
	const CUSTOMER = 'Khách hàng';
	const ADV_PACKAGE = 'Gói cước';
	const PRIORITY = 'Độ ưu tiên';
	const URL = 'Url';
	const FILE = 'File';
	const DESCRIPTION = 'Mô tả';
	const EXPIREDDATE = 'Ngày hết hạn';
	const SAVE = 'Save';
	const RESET = 'Reset';
	
	private function createIdElement() {
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
		return $id;
	}
	
	private  function createPageElement() {
		$notEmptyValidator = new Zend_Validate_NotEmpty();
		$notEmptyValidator->setMessage('Chưa chọn trang hiển thị');
		
		$page = new Zend_Form_Element_Select('page_id');
		$page->setLabel(self::PAGE)
			 ->setRequired(true)
			 ->addValidator($notEmptyValidator, true)
			 ->setAttrib('key', 'value')
			 ->addFilter('StringTrim')
			 ->setRegisterInArrayValidator(false);
		
		$page->addMultiOption("", "  Chọn trang hiển thị");
		return $page;
	}
	
	private  function createPositionElement() {
		$notEmptyValidator = new Zend_Validate_NotEmpty();
		$notEmptyValidator->setMessage('Chưa chọn vị trí hiển thị');
		
		$position = new Zend_Form_Element_Select('vi_tri');
		$position->setLabel(self::POSITION)
				 ->setRequired(true)
				 ->addValidator($notEmptyValidator, true)
				 ->setAttrib('key', 'value')
				 ->addFilter('StringTrim')
				 ->setRegisterInArrayValidator(false);
		
		$position->addMultiOption("", "  Chọn vị trí hiển thị");
		return $position;
	}
	
	private  function createCustomerElement() {
		$notEmptyValidator = new Zend_Validate_NotEmpty();
		$notEmptyValidator->setMessage('Chưa chọn khách hàng');
		
		$customer = new Zend_Form_Element_Select('id_khach_hang');
		$customer->setLabel(self::CUSTOMER)
				 ->setRequired(true)
				 ->addValidator($notEmptyValidator, true)
				 ->setAttrib('key', 'value')
				 ->addFilter('StringTrim')
				 ->setRegisterInArrayValidator(false);
		
		$customer->addMultiOption("", "  Chọn khách hàng");
		return $customer;
	}
	
	private  function createAdvPackageElement() {
		$notEmptyValidator = new Zend_Validate_NotEmpty();
		$notEmptyValidator->setMessage('Chưa chọn gói cước');
		
		$advPackage = new Zend_Form_Element_Select('id_goi_quang_cao');
		$advPackage->setLabel(self::ADV_PACKAGE)
				   ->setRequired(true)
				   ->addValidator($notEmptyValidator, true)
				   ->setAttrib('key', 'value')
				   ->addFilter('StringTrim')
				   ->setRegisterInArrayValidator(false);
		
		$advPackage->addMultiOption("", "  Chọn gói cước");
		return $advPackage;
	}
	
	private function createPriorityElement() {
		$priority = new Zend_Form_Element_Text('uu_tien');
		$priority->setLabel(self::PRIORITY)
			  ->setRequired(true)
			  ->addFilter('StringTrim')
			  ->addValidator('NotEmpty', true)
			  ->addValidator('Digits')
			  ->setAttribs(array("maxlength" => "9"));
		return $priority;
	}
	
	private function createUrlElement() {
		$url = new Zend_Form_Element_Text('url');
		$url->setLabel(self::URL)
			->addFilter('StringTrim')
			->setAttribs(array("maxlength" => "500"));
		return $url;
	}
	
	private function createExpiredDateElement() {
		$dateValidator = new Zend_Validate_Date(array('format' => 'dd-MM-yyyy', 'locale' => 'vi'));
		
		$expiredDate = new Zend_Form_Element_Text('ngay_het_han');
		$expiredDate->setLabel(self::EXPIREDDATE)
					->setDescription('Định dạng dd-mm-yyyy')
			  		->setRequired(true)
			  		->addFilter('StringTrim')
			  		->addValidator('NotEmpty', true)
			  		->addValidator($dateValidator);
		return $expiredDate;
	}
	
	private function createFileElement() {
		$image = new Zend_Form_Element_File('image_url');
        $image->setLabel(self::FILE)
        	  ->setAttribs(array('style' => 'font-size: 18px', 'size' => '36'));
		return $image;
	}
	
	private function createDescriptionElement() {
		$description = new Zend_Form_Element_Textarea('mota');
		$description->setLabel(self::DESCRIPTION)
				   	->addFilter('StringTrim')
				   	->addFilter('StripTags')
				   	->setAttribs(array("style" => "width: 400px; height: 250px;", "maxlength" => "255"));
		return $description;
	}
	
	private function createSubmitElement() {
		$submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
        	   ->removeDecorator('DtDdWrapper')
        	   ->setLabel(self::SAVE)
        	   ->setAttrib("class", "btn btn-large btn-primary ");
       	return $submit;
	}
	
	private function createResetElement() {
		$reset = new Zend_Form_Element_Reset('reset'); 
		$reset->setAttrib('id', 'resetbutton')
			  ->removeDecorator('DtDdWrapper')
			  ->setLabel(self::RESET)
			  ->setAttrib("class", "btn btn-large");
		return $reset;	  
	}
	
    public function init() {
        $this->setName('quangcao');
        $this->setMethod('post');

		$id = $this->createIdElement();
		$position = $this->createPositionElement();
		$page = $this->createPageElement();
		$customer = $this->createCustomerElement();
		$advPackage = $this->createAdvPackageElement();
		$priority = $this->createPriorityElement();
		$expiredDate = $this->createExpiredDateElement();
		$file = $this->createFileElement();
		$description = $this->createDescriptionElement();
		$submit = $this->createSubmitElement();
		$reset = $this->createResetElement();
		$url = $this->createUrlElement();
        
        $this->addElements(array($id, $page, $position, $customer, $advPackage, $url, $priority, $expiredDate, $file, $description, $submit, $reset));
        
		$this->addDisplayGroup(array('submit', 'reset'), 'buttons');
		$dg = $this->getDisplayGroup('buttons');
		$dg->removeDecorator('Fieldset');
		$dg->removeDecorator('HtmlTag');      
    }
	
}
?>